//
//  RregistViewControllerc.m
//  EPAa
//
//  Created by lanou3g on 16/4/28.
//  Copyright © 2016年 李日青. All rights reserved.
//

#import "RregistViewControllerc.h"
#import "RNetWorkRequestManager.h"
@interface RregistViewControllerc ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *emailLabel;
@property (weak, nonatomic) IBOutlet UITextField *unameLabel;
@property (weak, nonatomic) IBOutlet UITextField *passwordLabel;
@property (weak, nonatomic) IBOutlet UIImageView *unameImageView;

@end

@implementation RregistViewControllerc

- (void)viewDidLoad {
    [super viewDidLoad];
    self.unameImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *singletap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageButton)];
    [self.unameImageView addGestureRecognizer:singletap];
    // Do any additional setup after loading the view from its nib.
}
- (void)imageButton {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"从本地选取图片" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController *pickC = [[UIImagePickerController alloc]init];
        pickC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        pickC.delegate = self;
        [self presentViewController:pickC animated:YES completion:nil];
        
    }];
    [alertC addAction:alertA];
    [self presentViewController:alertC animated:YES completion:nil];
}

- (IBAction)didClickregistBurron:(id)sender {
        [RNetWorkRequestManager requestURL:[NSURL URLWithString:@"http://api2.pianke.me/user/reg"] Method:CK_POST Params:@{@"email":self.emailLabel.text, @"gender" :@0 ,@"uname":self.unameLabel.text,@"passwd":self.passwordLabel.text} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSString *str = jsonDict[@"data"][@"msg"];
            str = str ? str : @"注册成功";
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *alettA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if ([str isEqualToString:@"注册成功"]) {
                    self.image (self.unameImageView.image);
                    self.label (self.emailLabel.text);
                }
            }];
            [alertC addAction:alettA];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
        }];
    

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    self.unameImageView.image = info[@"UIImagePickerControllerOriginalImage"];
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    dispatch_async(dispatch_get_main_queue(), ^{
        
    });
    
}
- (IBAction)didClickbackButton:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
